<?php
include_once 'data.php';

if (isset($_GET['file'])) {
	if (!isset($_SESSION['session_clipboard'])) {
		$_SESSION['session_clipboard'][] = $_GET['file'];
		echo "added";
	} else {
		if (!in_array($_GET['file'], $_SESSION['session_clipboard'])) {
			$_SESSION['session_clipboard'][] = $_GET['file'];
			$_SESSION['session_clipboard'] = array_unique($_SESSION['session_clipboard']);
			echo "added";
		} else {
			$key = array_search($_GET['file'], $_SESSION['session_clipboard']);
			unset($_SESSION['session_clipboard'][$key]);
                     if (isset($_GET['selection']) && $_GET['selection'] == 'clipboard') {
                        $id = array_search($_GET['file'], $_SESSION['export_files']);
                        if ($id !== false) {
                            unset($_SESSION['export_files'][$id]);
                            $_SESSION['export_files'] = array_values($_SESSION['export_files']);
                        }
                     }
			echo "removed";
		}
	}
}
?>